
package com.loan.rebate.common.tags;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

/**
 * 标签展示
 *
 * @author 朱国军
 * @since 1.0
 * @version 2016年6月25日 朱国军
 */
public class KeyWordsTag extends TagSupport {
    
    /** 版本号 */
    private static final long serialVersionUID = 1548904743061435167L;
    
    private static Logger logger = Logger.getLogger(KeyWordsTag.class);
    
    private String keyWords;
    
    /**
     * 获取
     *
     * @return
     */
    public String getKeyWords() {
        return keyWords;
    }
    
    /**
     * 设置
     *
     * @param keyWords
     */
    public void setKeyWords(String keyWords) {
        this.keyWords = keyWords;
    }

    @Override
    public int doEndTag() throws JspException {
        return PaginationTag.EVAL_PAGE;
    }

    @Override
    public int doStartTag() throws JspException {
        StringBuilder builder = new StringBuilder();
        if (StringUtils.isNotBlank(keyWords)) {
            String[] keyWordList = keyWords.split(",");
            for (String keyWord : keyWordList) {
                if (StringUtils.isNotBlank(keyWord)) {
                    builder.append("<a href='#' title='").append(keyWord).append("' target='_blank'>").append(keyWord).append("</a>");
                }
            }
        }
        JspWriter writer = this.pageContext.getOut();
        try {
            writer.write(builder.toString().trim());
        } catch (IOException e) {
            logger.error("字典项转radio的Tag出错", e);
        }
        return PaginationTag.SKIP_BODY;
    }
}
